/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.testingProject.view;

import javax.swing.JTabbedPane;
import org.colswe.testingProject.control.CRUDUsersControl;
import org.colswe.testingProject.entity.Person;

/**
 *
 * @author Leonardo Bohórquez
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public static JTabbedPane tbpnlTabs;
    private WelcomePanel pnlWelcome;
    public static AdminUserPanel pnlAdminUser;
    private CRUDUsersControl cruduc;
    private String loggedUser;

    public MainFrame() {
        initComponents();
    }

    public void init(String role,String userName) {
        tbpnlTabs = new JTabbedPane();
        pnlWelcome = new WelcomePanel(loggedUser);
        tbpnlTabs.add(pnlWelcome);
        tbpnlTabs.setTitleAt(0, "Pantalla de Bienvenida");
        if (role.equals(Person.ADMINISTRATOR)) {
            pnlAdminUser = new AdminUserPanel();
            tbpnlTabs.add(pnlAdminUser);
            tbpnlTabs.setTitleAt(1, "Administración de usuarios");
        } else if (role.equals(Person.USERS_ADMINISTRATOR)) {
        }
        pnlMainPanel.setVisible(false);
        pnlMainPanel.removeAll();
        pnlMainPanel.add(tbpnlTabs);
        pnlMainPanel.setVisible(true);
        this.loggedUser=userName;
        cruduc=new CRUDUsersControl();
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlMainPanel = new javax.swing.JPanel();
        mnubMenuBar = new javax.swing.JMenuBar();
        mnuFile = new javax.swing.JMenu();
        mnuiRefresh = new javax.swing.JMenuItem();
        mnuiExit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1000, 650));
        setResizable(false);

        pnlMainPanel.setLayout(new java.awt.BorderLayout());

        mnuFile.setMnemonic('A');
        mnuFile.setText("Archivo");

        mnuiRefresh.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        mnuiRefresh.setMnemonic('c');
        mnuiRefresh.setText("Actualizar");
        mnuiRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuiRefreshActionPerformed(evt);
            }
        });
        mnuFile.add(mnuiRefresh);

        mnuiExit.setText("Salir");
        mnuiExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuiExitActionPerformed(evt);
            }
        });
        mnuFile.add(mnuiExit);

        mnubMenuBar.add(mnuFile);

        jMenu2.setText("Editar");
        mnubMenuBar.add(jMenu2);

        setJMenuBar(mnubMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlMainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlMainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuiExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiExitActionPerformed
    }//GEN-LAST:event_mnuiExitActionPerformed

    private void mnuiRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiRefreshActionPerformed
        LoginWindow.mf.pnlAdminUser.tblUsers.setModel(cruduc.showResults(null,null));
    }//GEN-LAST:event_mnuiRefreshActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /*
//         * Set the Nimbus look and feel
//         */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /*
//         * If Nimbus (introduced in Java SE 6) is not available, stay with the
//         * default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /*
//         * Create and display the form
//         */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new MainFrame().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu mnuFile;
    private javax.swing.JMenuBar mnubMenuBar;
    private javax.swing.JMenuItem mnuiExit;
    private javax.swing.JMenuItem mnuiRefresh;
    private javax.swing.JPanel pnlMainPanel;
    // End of variables declaration//GEN-END:variables
}
